#ifndef TCPSOCKET_H
#define TCPSOCKET_H
#include "server.h"
#include <event2/bufferevent.h>  // 必须包含！提供 bufferevent 类型定义
#include <stdint.h>             // 提供 uint16_t 类型
#include <arpa/inet.h>          // 提供 inet_ntop 等

class Tcpserver;

class Tcpsocket
{
public:
    Tcpsocket(bufferevent *ev,Tcpserver*server,char*ip,uint16_t prot);
    static void Readeventcb(struct bufferevent *bev, void *ctx);
    static void Writeevnetcb(struct bufferevent *bev, void *ctx);
    static void Closeeventcb(struct bufferevent *bev, short what, void *ctx);
    char*getip();
    u_int16_t getPort();

    //实现读写
    int read(void*data,int size);
    int write(void*data,int size);
    void setuserName(std::string name);
    std::string getuserName();
private:
    char*ip;
    bufferevent*ev;//与客户端沟通
    uint16_t prot;
    static Tcpserver*server;//服务器实例
    std::string userName;

};

#endif // TCPSOCKET_H
